function changePage(url) {
	$("#pageIframe").attr("src", url);
};

function changeUI() {
	var path = $("#changeUISelect").val();
	$.post("/saveIndexUI", {
		"path" : path
	}, function(data, status) {
		parent.window.location.href = "/index";
	});
}
function initChangeUI() {
	layer.open({
		type : 2,
		title : "桌面样式",
		shadeClose : true,
		offset : 15,
		shade : false,
		maxmin : true, // 开启最大化最小化按钮
		area : [ '400px', '200px' ],
		maxmin : true,
		content : '/indexUIPage'
	});
}

// function initChangeUI() {
// try {
// $("#changeUIDiv")
// .append(
// " <select id = 'changeUISelect' onchange='changeUI()'></select>");
//
// $
// .post(
// "/indexUI",
// function(data, status) {
// if (data == "/platform/index/index") {
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index' selected =
// 'selected'>AdminEx</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-win10'>win10</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-xadmin'>xadmin</option>");
//
// } else if (data == "/platform/index/index-win10") {
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index'>AdminEx</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-win10' selected =
// 'selected'>win10</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-xadmin'>xadmin</option>");
//
// } else if (data == "/platform/index/index-xadmin") {
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index'>AdminEx</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-win10'>win10</option>");
// $("#changeUISelect")
// .append(
// "<option value='/platform/index/index-xadmin' selected =
// 'selected'>xadmin</option>");
//
// }
// });
//
// } catch (e) {
// }
// }

$(function() {
	$("#pageIframe").attr("src", "/deskTop/mydesktop");
	// 初始化目标
	$
			.post(
					"/deskTop/getGoal",
					function(data, status) {
						$("#goalBadge").html(data.length);
						$("#goalBadgeTitle")
								.html("还有" + data.length + "个目标未达成");
						var goalDropdownListStr = "";

						for (var i = 0; (i < data.length && i < 4); i++) {
							goalDropdownListStr = goalDropdownListStr
									+ ' <li> <div class="task-info"> <div>'
									+ data[i].name + '</div></div>';
							goalDropdownListStr = goalDropdownListStr
									+ '<div class="progress progress-striped">';
							goalDropdownListStr = goalDropdownListStr
									+ '<div style="width: '
									+ data[i].percent
									+ '%" aria-valuemax="100" aria-valuemin="0" aria-valuenow="'
									+ data[i].percent + '" role="progressbar"';
							if (data[i].percent > 50) {
								goalDropdownListStr = goalDropdownListStr
										+ 'class="progress-bar progress-bar-info">"';
							} else {
								goalDropdownListStr = goalDropdownListStr
										+ 'class="progress-bar progress-bar-danger">';
							}

							goalDropdownListStr = goalDropdownListStr
									+ '<span class="">' + data[i].percent
									+ '% </span></div></div></li>';

						}
						goalDropdownListStr = goalDropdownListStr
								+ '<li class="new"><a href="javascript:changePage(\'/goal/list\')">查看所有目标</a></li>';

						$("#goalDropdownList").html(goalDropdownListStr);

					});
	// initChangeUI();
});

function logonPZGLGJ() {
	window.open("http://10.23.13.92:8888/sword?ctrl=PzglLoginCtrl_initLogin");
	// user = $("#useraccount").val();
	// openPostWindow(
	// "http://10.23.13.92:8888/form.sword",
	// '{"tid":"","ctrl":"PzglLoginCtrl_handleLogin","page":"","data":[{"name":"user","value":"'
	// + user
	// +
	// '","sword":"attr"},{"name":"password","value":"css123","sword":"attr"}]}',
	// "postData");
}
function logonWTGLPT() {
	window.open("http://10.23.8.160:8001/");
	// user = 'wanxu';// $("#useraccount").val();
	//	
	//	
	//
	// var str =
	// '{"tid":"","ctrl":"XTGL001LoginCtrl_handleLogin?sName=XTGL001LoginCtrl_handleLogin","page":null,"data":[{"sword":"attr","name":"userName","value":"'
	// + user
	// +
	// '"},{"sword":"attr","name":"userPwd","value":"Abcd1234"}],"bindParam":true}';
	//	
	// str = encodeURI(str);
	// $.ajax({
	// type : "get",
	// url : "http://10.23.8.160:8001/ajax.sword",/* url写异域的请求地址 */
	// dataType : "jsonp",/* 加上datatype */
	// data : {
	// "postData" : str
	// },
	// jsonpCallback : "cb",/* 设置一个回调函数，名字随便取，和下面的函数里的名字相同就行 */
	// success : function() {
	// alert();
	// }
	// });

}
function logonSJYGLGJ() {

	// var loginData =
	// "{\"tid\":\"\",\"ctrl\":\"LoginCtrl_handleLogin\",\"page\":\"\",\"data\":[{\"name\":\"user\",\"value\":\"zhaojiping\",\"sword\":\"attr\"},{\"name\":\"password\",\"value\":\"css123\",\"sword\":\"attr\"}]}";
	// openPostWindow(
	// "http://10.23.13.92:8090/ajax.sword?sName=LoginCtrl_handleLogin",
	// loginData, "postData");
	window.open("http://10.23.13.92:8090/sword?ctrl=LoginCtrl_initLogin");
}
function openPostWindow(action, data, inputName) {
	// 创建Form
	var form = $('<form></form>');
	// 设置属性
	form.attr('action', action);
	form.attr('method', 'post');
	// form的target属性决定form在哪个页面提交
	// _self -> 当前页面 _blank -> 新页面
	form.attr('target', '_blank');
	// 创建Input
	var my_input = $('<input type="text" name="' + inputName + '" />');
	my_input.attr('value', data);
	// 附加到Form
	form.append(my_input);

	$(document.body).append(form); // 使用JQuery将上述表单加入到body中
	// 提交表单
	form.submit();
	// 注意return false取消链接的默认动作
	return false;
}
